<?php
namespace Home\Controller;
use Think\Controller;


class QuotationlistController extends Controller {

      //发布报价 信息
	function publishQuotation(){
        $mask=$_POST["mask"];
		$quotation=M("Quotationlist");
		$data["quotationlist_place"]=$_POST["place"];
		$data["quotationlist_number"]=$_POST["number"];
		$data["quotationlist_price"]=$_POST["price"];
		$data["quotationlist_desc"]=$_POST["desc"];
		$data["user_id"]=$_POST["userid"];
		$data["user1_id"]=$_POST["userid1"];
		$data["quotationlist_time"]=date('Y-m-d H:i:s',time());
		$data["goodsname"]=$_POST["goodsname"];
        $data["quotationlist_mark"]=$mask;
		$result=$quotation->add($data);
		  if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"报价成功!"
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"报价失败！"
		        ),"JSON");
		 }
	}
     


     //卖家查询买家已查看的信息
	function inqureAlrQuotation(){
		$quotationlist=M("Quotationlist");

       $userid=$_POST["userid"];
       $quotationmark=$_POST["quotationlistmark"];

       $data["user_id"] = $userid;
       $data["quotationlist_mark"]=$quotationmark;
         //添加条件查询
      $result=$quotationlist
      ->where($data)
      ->select();       
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"查询成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"查询失败","data"=>NULL),"JSON");
       }
	}


	
    //买家查询卖家已报价信息
    function inqureSellerQuotation(){
		$quotation=M("Quotationlist");

		$userid1=$_POST["userid1"];
		$mask=$_POST["mask"];

		$result=$quotation->where("user1_id='$userid1' and quotationlist_mark='$mask'")->select();
		  if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"查询成功!",
		        "result"=>$result
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"查询失败！"
		        ),"JSON");
		 }
	}



//买家同意报价

  function argeeQuotation(){

  	   $quotation=M("Quotationlist");
        $quoid=$_POST["quoid"];
		$mask=$_POST["mask"];
        $agreetime=$_POST["agreetime"];
        
        $data["quotationlist_id"]=$quoid;
        $data["mask"]=$mask;
        $data["agreetime"]=$agreetime;

		$result=$quotation->save($data);
		  if ($result) {
		     $this->ajaxReturn(array(
		        "code"=>200,
		        "message"=>"同意报价!"
		        ),"JSON");
		 }
		 else{
		     $this->ajaxReturn(array(
		        "code"=>500,
		        "message"=>"同意报价失败！"
		     ),"JSON");
          }


     }

////////////////////////////////////////////////////////////////////////////////////////////////
     public function lookquotationMark(){

       $quotationlist=M("Quotationlist");
       $userid=$_POST["userid"];
       $data["user1_id"] = $userid;
         //添加条件查询
          $result=$quotationlist  
          ->field("t_quotationlist.quotationlist_mark")  
          ->where($data)
          ->select();        
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"查询成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"查询失败","data"=>NULL),"JSON");
       }  
    }
    public function lookquotationinfo(){
       $quotationlist=M("Quotationlist");
       $userid=$_POST["userid"];
       $data["user1_id"] = $userid;
         //添加条件查询
          $result=$quotationlist  
          ->field("t_user.user_id,t_user.user_phone,t_user.user_nick,t_quotationlist.quotationlist_id,t_quotationlist.quotationlist_place,t_quotationlist.quotationlist_number,t_quotationlist.quotationlist_price,t_quotationlist.quotationlist_desc,t_quotationlist.quotationlist_mark,t_quotationlist.goodsname,t_quotationlist.quotationlist_time") 
          ->join("t_user on t_quotationlist.user_id=t_user.user_id")
         
          ->where($data)
          ->select();        
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"查询成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"查询失败","data"=>NULL),"JSON");
       }  

    }
    //修改未读与已读
    public function updatequotationinfo(){
        $quotationlist=M("Quotationlist");

       $quotationid=$_POST["quotationlistid"];
       $quotationmark=$_POST["quotationlistmark"];
       $data["quotationlist_id"] = $quotationid;
       $data["quotationlist_mark"]=$quotationmark;
         //添加条件查询
      $result=$quotationlist->save($data);       
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"修改成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"修改失败","data"=>NULL),"JSON");
       }  

    }

    //查询未读

     public function unreadquotationinfo(){
       $quotationlist=M("Quotationlist");

       $userid=$_POST["userid"];
       $quotationmark=$_POST["quotationlistmark"];

       $data["user1_id"] = $userid;
       $data["quotationlist_mark"]=$quotationmark;
         //添加条件查询
      $result=$quotationlist
      ->field("t_user.user_id,t_user.user_nick,t_quotationlist.quotationlist_id,t_quotationlist.quotationlist_place,t_quotationlist.quotationlist_number,t_quotationlist.quotationlist_price,t_quotationlist.quotationlist_desc,t_quotationlist.quotationlist_mark,t_quotationlist.goodsname,t_quotationlist.quotationlist_time") 
      ->join("t_user on t_quotationlist.user_id=t_user.user_id")
      ->where($data)
      ->select();       
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"查询成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"查询失败","data"=>NULL),"JSON");
       }  

    }
    //查询未读
     public function updaterefused(){
        $quotationlist=M("Quotationlist");

       $quotationid=$_POST["quotationlistid"];
       $quotationmark=$_POST["user1id"];
       $data["quotationlist_id"] = $quotationid;
       $data["user1_id"]=$quotationmark;
         //添加条件查询
      $result=$quotationlist->save($data);       
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"修改成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"修改失败","data"=>NULL),"JSON");
       }  

    }



    //同意
    public function agreequotationinfo(){
        $quotationlist=M("Quotationlist");

       $quotationid=$_POST["quotationlistid"];
       $quotationmark=$_POST["quotationlistmark"];
       $agreetime=date('Y-m-d H:i:s',time());
       $data["quotationlist_id"] = $quotationid;
       $data["quotationlist_mark"]=$quotationmark;
       $data["agreetime"]=$agreetime;
  
         //添加条件查询
      $result=$quotationlist->save($data);       
       if ($result) {
          $this->ajaxReturn(array("code"=>200,"message"=>"修改成功","data"=>$result),"JSON");
       }else{
            $this->ajaxReturn(array("code"=>500,"message"=>"修改失败","data"=>NULL),"JSON");
       }  

    }







}